const req = require("request");

// let arr = [
//     {
//         workspace,
//         name,
//         path
//     }
// ];
module.exports = (arr) => {
    return new Promise((suc,fail) => {
        req({
            url: "http://11.11.11.164:8000/publish/",
            method: "POST",
            json: true,
            headers: {
                "content-type": "application/json",
            },
            body: arr
        }, function(error, response, body) {
            if (error) {
                fail("严重错误:" + error.message);
            } else {
                if (typeof body === 'object') {
                    if (body.code === 200) {
                        suc(null,body.msg);
                    } else {
                        fail(body);
                    }
                } else {
                    fail("未知错误，发布接口返回内容不是 json ");
                }
            }
        });
    });
};

// req({
//     url: "http://11.11.11.164:8000/publish/",
//     method: "POST",
//     json: true,
//     headers: {
//         "content-type": "application/json",
//     },
//     body: [{
//         workspace: 'test',
//         name: 'fewe',
//         path: 'Z:\\test\\avi-2018-1.tif'
//     }]
// },(err,resp,body) => {
//     console.log(err,resp,body);
// });
